package com.advaita.gui;

import java.awt.*;

import javax.swing.*;
import javax.swing.border.TitledBorder;

import com.advaita.license.Customer;
import com.advaita.license.Selection;
import com.advaita.util.*;

public class AnalysisTab extends JPanel {
	private static final Insets WEST_INSETS = new Insets(5, 0, 5, 5);
	private static final Insets EAST_INSETS = new Insets(5, 5, 5, 0);
	
	private GridBagConstraints createGbc(int x, int y) {
		GridBagConstraints gbc = new GridBagConstraints();
		gbc.gridx = x;
		gbc.gridy = y;
		gbc.gridwidth = 1;
		gbc.gridheight = 1;

		gbc.anchor = (x == 0) ? GridBagConstraints.WEST
				: GridBagConstraints.EAST;
		gbc.fill = (x == 0) ? GridBagConstraints.BOTH
				: GridBagConstraints.HORIZONTAL;

		gbc.insets = (x == 0) ? WEST_INSETS : EAST_INSETS;
		gbc.weightx = (x == 0) ? 0.1 : 1.0;
		gbc.weighty = 1.0;
		return gbc;
	}
	
	AnalysisTab(Customer customer) {

		Dimension size = getPreferredSize();
		size.width = 250;
		size.height = 350;
		setPreferredSize(size);

		setBorder(BorderFactory.createTitledBorder(null, "Analysis Type",
				TitledBorder.LEFT, TitledBorder.TOP, new Font("Serif",
						Font.ITALIC + Font.BOLD, 20)));

		setLayout(new GridBagLayout());
		GridBagConstraints c = new GridBagConstraints();

		SetupComboBox setupComboBox = new SetupComboBox();
		Object[] items = { new ComboItem("Differentially Expressed"), 
				new ComboItem("All Genes")};
		
		Object[] items1 = new ComboItem[4];
		
		int index =0;
		for (Selection analysisIterator : customer.licenseInfo.getAnalysis()) {
			//	System.out.println("Analysis : " + analysisIterator.getSelection()
			//			+ "  ( " + analysisIterator.getIsEnabled() + " )");
			items1[index]=new ComboItem(analysisIterator.getSelection(),
				                    	analysisIterator.getIsEnabled());
			index ++;
		}
		
		
		JComboBox combo = new JComboBox(items);
		combo.setRenderer(new ComboRenderer());
		combo.addActionListener(new ComboListener(combo));

		JComboBox combo1 = new JComboBox(items1);
		combo.setRenderer(new ComboRenderer());
		combo.addActionListener(new ComboListener(combo1));
		
		JLabelAllinOne label1 = new JLabelAllinOne("     Analysis Type", "Serif",
				Font.PLAIN, Font.ITALIC, 18);
		c.gridx = 0; c.gridy = 0;
		c.weightx=1; c.weighty=1;
		c.fill = GridBagConstraints.HORIZONTAL;
		c.anchor = GridBagConstraints.NORTHWEST;
		
		c = createGbc(0, 0);
		c.anchor=GridBagConstraints.CENTER;
		c.weightx=1;
		c.weighty=1;
		c.fill=GridBagConstraints.BOTH;
		add(label1, c);
		
		c=createGbc(1,0);
		add(combo, c);
		
		JLabelAllinOne label2 = new JLabelAllinOne("     Analysis Engine", "Serif",
				Font.PLAIN, Font.ITALIC, 18);
		c.gridx = 0; c.gridy = 1;
		c.weightx=1;
		c.fill = GridBagConstraints.HORIZONTAL;
		c.anchor = GridBagConstraints.NORTHWEST;
		add(label2, c);
		
		c.gridx = 1; c.gridy = 1;
		add(combo1, c);

	}
}